namespace hjc {

	export class ScanSystem extends hjc.System {
		protected $concerns = [Scanner];

		protected execute(entities: hjc.Entity[]): void {
			entities.forEach(entity => {
				if (entity.scanner.checkPfc()) this._toScan(entity);
			});
		}

		private _toScan(entity: Entity): void {
			let scanner = entity.scanner;
			if (!entity.hasFunc(Func.Entity.onFound) || !entity.doFunc(Func.Entity.onPrepared)) return;
			else if (!scanner.interest || scanner.span <= 0) return;
			else {
				let targets = game.entities(scanner.interest).filter(target => entity !== target && entity.distTo(target) <= scanner.span);
				if (targets.length > 0) entity.doFunc(Func.Entity.onFound, targets);
			}
		}
	}
}